There are two ways to iterate rows in the grid:
-
Classic iterator;
-
Built-in iterator.
Classic iterator
for (var i=0; i<grid.getRowsCount(); i++){
// here i - index of row in grid
do_something_with_row(index);
}
This way of iteration has the following characteristics:
-
Used parameter - index (not ID), zero based position of a row in the grid;
-
The order of iteration equals the order of elements in the grid;
-
In case of paging mode - only current page is iterated;
-
In case of tree grid - only currently visible rows are iterated;
-
In case of smart rendering mode - not usable;
-
In case of applied filtering - only rows that accept filtering rules will be included in iteration.
Built-in iterator
grid.forEachRow(function(id){
// here id - row ID
do_something_with_row(id);
})
This way of iteration has the following characteristics:
-
Used parameter - row ID;
-
Order of iteration is not equal to the current rows order in grid (basically it is equal to the adding order of rows to the grid, but it can be inconsistent);
-
In case of paging or smart rendering mode - all rows parsed at the current moment will be affected;
-
In case of tree grid - all rows will be processed, including those in closed branches;
-
In case of applied filtering - all rows in the grid (including filtered out ones) will be included in iteration.
The cells iteration is more simple task, but it also has two possible ways:
-
Classic cell iteration;
-
Built-in cell iteration.
Classic cell iteration
for (var i=0; i<grid.getColumnCount(); i++){
// i - column index
alert(grid.cells(id,i).getValue());
}
Built-in cell iteration
grid.forEachCell(id,function(c){
alert(c.getValue());
});
There is
no fundamental
difference between two cell iteration approaches.
Iteration through TreeGrid
You can loop from all child-rows of some row in treegrid as
grid._h2.forEachChild(parent_id,function(element){
//element.id - id of child row
//element.parent.id - parent id
do_something_with_row(element.id);
});
where parent_id - id of rows, against which functionality will be executed.
Iteration through rows in grop ( grid after groupBy )
You can loop through all rows in some group by
mygrid.forEachRowInGroup(name,function(id){
do_something_with_row(id);
});
where name - key-value of group